<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;

        }

        div {
            width: 35px;
            border: 1px solid;
            display: none;
        }

        p:hover {
            background: red;
        }
    </style>
</head>

<body>
    <button>输入法</button>
    <div>
        <p>简写</p>
        <p>拼音</p>
        <p class="p" style="border-top: 1px solid;">关闭</p>
    </div>
</body>

</html>
<script>
    let btn = document.querySelector("button")
    let div = document.querySelector("div")
    let p = document.querySelector(".p")
    btn.onclick = function () {
        if (div.style.display != 'block') {
            div.style.display = 'block'
        } else {
            p.onclick()
        }
    }
    p.onclick = function () {
        div.style.display = 'none'
    }
</script>